package com.weixin.paleituo.factory;

import android.support.v4.app.Fragment;

import com.weixin.paleituo.fragment.AreadAppoinmentFragment;
import com.weixin.paleituo.fragment.AreadVisterAppoinmentFragment;
import com.weixin.paleituo.fragment.CancelAppoinmentFragment;
import com.weixin.paleituo.util.LogUtils;

import java.util.HashMap;

/**
 * Author yichao
 * Time  2017/11/30 9:36
 * Dest  预约fragment的工厂
 */
public class AppoinmentFragmentFactory {
    public static String TAG = "AppoinmentFragmentFactory";
    private static final int ALREADAPPOINTMENT_FRAGMENT = 0;
    private static final int ALREADVISTERAPPOINMENNT_FRAGMENT = 1;
    private static final int CANCELAPPOINMENT_FRAGMENT = 2;

    private static HashMap<Integer, Fragment> mMap = new HashMap();


    public static Fragment getFragment(int index) {
        Fragment fragment = null;
        if (mMap.containsKey(index)) {
            fragment = mMap.get(index);
            LogUtils.i(TAG, "复用" + index);
        } else {
            switch (index) {
                case ALREADAPPOINTMENT_FRAGMENT:
                    fragment = new AreadAppoinmentFragment();
                    break;
                case ALREADVISTERAPPOINMENNT_FRAGMENT:
                    fragment = new AreadVisterAppoinmentFragment();
                    break;
                case CANCELAPPOINMENT_FRAGMENT:
                    fragment = new CancelAppoinmentFragment();
                    break;
            }
            LogUtils.i(TAG, "新建" + index);
            mMap.put(index, fragment);
        }
        return fragment;

    }


}
